import fetch from 'common/src/utils/fetch';
import UTILS from "common/src/utils/utils";

// let apiPrefix = '/dev';
let apiPrefix = '/api/studentservice/';
function dealQeury(params) {
  let query = '?';
  for (let key in params) {
    query += key;
    query += '=';
    query += params[key];
    query += '&';
  }
  return query.substring(0, query.length - 1)
}
/**
 * 查询
 * @param data
 */
export function queryPaperTime(id, deptId) {
  return fetch({
    url: apiPrefix + 'requireScore/queryPaperTime?studentId='+id+'&deptId='+deptId,
    method: 'get'
  })
}

/**
 * 根据学生ID查询选题申请信息
 * @param data
 */

export function queryPaperById(params) {
  return fetch({
    url: `${apiPrefix}requireScore/queryPaperStudent${dealQeury(params)}`,
    method: 'get'
  })
}

/**
 * 根据学生ID查询选题申请信息
 * @param data
 */
export function queryPaperStudent(id, topicType) {
  return fetch({
    url: `${apiPrefix}requireScore/queryPaperStudent?studentId=${id}&topicType=${topicType}`,
    method: 'get'
  })
}

/**
 * 新增正常选题规则保存
 * @param data
 */

export function saveNormalPaper(data) {
  return fetch({
    url: `${apiPrefix}requireScore/saveNormalPaper`,
    method: 'post',
    data
  })
}

/**
 * 新增缓选题规则保存
 * @param data
 */

export function saveCachedPaper(data) {
  return fetch({
    url: `${apiPrefix}requireScore/saveCachedPaper`,
    method: 'post',
    data
  })
}
/**
 * 根据学生ID查询选题申请信息
 * @param data
 */
export function queryAllPaperInfo(data) {
  return fetch({
    url: `${apiPrefix}requireScore/queryAllPaperInfo`,
    method: 'post',
    data
  })
}

/**
 * 查询章节模板信息
 * @param data
 */
export function queryChapterInfo(id, studentId) {
  return fetch({
    url: `${apiPrefix}requireScore/queryChapterInfo?paperId=${id}&studentId=${studentId}`,
    method: 'get',
  })
}

/**
 * 查询章节信息
 * @param data
 */
export function queryDetailByPaperId(id) {
  return fetch({
    url: `${apiPrefix}requireScore/queryDetailByPaperId?paperId=${id}`,
    method: 'get',
  })
}
/**
 * 提交章节信息
 * @param data
 */
export function submitNormalPaper(data) {
  return fetch({
    url: `${apiPrefix}requireScore/submitNormalPaper`,
    method: 'post',
    data
  })
}

/**
 * 选题基本规则
 * @param data
 */
export function queryAllPaperById(id) {
  return fetch({
    url: `${apiPrefix}requireScore/queryAllPaperById?paperId=${id}`,
    method: 'get',
  })
}

/**
 * 选题基本规则
 * @param data
 */
export function exportPaperInfoList(data) {
  return fetch({
    url: `${apiPrefix}requireScore/exportPaperInfoList`,
    method: 'post',
    responseType: 'blob',
    data
  })
}
/**
 * 中期考核方案二导出
 * @param {*} id 
 */
export function exportPaperInfoPdf2(id) {
  return `${apiPrefix}requireScore/exportPaperInfoPdf2?paperId=${id}&exportType=2`
}
/**
 * 预览个人小结pdf部分
 * @param {*} id 
 */
export function previewPersonTitle(id,studentId) {
  return `${apiPrefix}requireScore/previewPersonTitle?applyId=${id}&exportType=2&studentId=${studentId}`
}
/**
 * 选题结果查询
 * @param data
 */
export function findResultQuery(data) {
  return fetch({
    url: `${apiPrefix}requireScore/findResultQuery`,
    method: 'post',
    data
  })
}

/**
 * 选题结果查询导出
 * @param data
 */
export function exportResultQuery(data) {
  return fetch({
    url: `${apiPrefix}requireScore/exportResultQuery`,
    method: 'post',
    data: data,
    responseType: 'blob'
  })
}

/**
 * 选题结果汇总导出
 * @param data
 */
export function exportResultSum(data) {
  return fetch({
    url: `${apiPrefix}requireScore/exportResultSum`,
    method: 'post',
    data: data,
  }).then(res => {
    UTILS.downloadFile(res, 'ResultSum.xls', 'application/vnd.ms-excel;charset=utf-8');
  });
}

export function paperRecall(data) {//撤回
  return fetch({
    url: `${apiPrefix}requireScore/recallRequirePaper?paperId=${data}`,
    method: 'post'
  })
}

export function reverseAudit(data) {//反审核(撤回)
  return fetch({
    url: `${apiPrefix}requireScore/reverseAuditRequirePaper?paperId=${data}`,
    method: 'post'
  })
}

// 撤回审批
//http://127.0.0.1:8110/requireScore/batchReverseAudit 
export function batchReverseAudit(data) {
  return fetch({
    url: `${apiPrefix}requireScore/batchReverseAudit`,
    method: 'post',
    data
  })
}

export function queryIsApply(id) {//论文工作申请页面查询数据是否可编辑
  return fetch({
    url: `${apiPrefix}requireScore/queryIsApply?studentId=${id}`,
    method: 'get'
  })
}

/**
 * @param data
 * 论文选题工作申请导出中文Word
 */
export function exportPaperInfoWordCN(id) {
  return `${apiPrefix}requireScore/exportPaperInfoWord?paperId=${id}&language=cn`
}
/**
 * @param data
 * 论文选题工作申请导出中文PDF
 */
export function exportPaperInfoPdfCN(id) {
  return `${apiPrefix}requireScore/exportPaperInfoPdf?paperId=${id}&exportType=2&language=cn`
}

/**
 * @param data
 * 论文选题工作申请导出英文Word
 */
export function exportPaperInfoWordEN(id) {
  return `${apiPrefix}requireScore/exportPaperInfoWord?paperId=${id}&exportType=2&language=en`
}
/**
 * @param data
 * 论文选题工作申请导出英文PDF
 */
export function exportPaperInfoPdfEN(id) {
  return `${apiPrefix}requireScore/exportPaperInfoPdf?paperId=${id}&exportType=2&language=en`
}

export default {
  findResultQuery
}

//论文选题最终版本上传
export function addFinalVersion(data) {
  return fetch({
    url: `${apiPrefix}version/addFinalVersion`,
    method: 'post',
    data
  })
}

//论文选题最终版本查询
export function queryFinalVersion(data) {
  return fetch({
    url: `${apiPrefix}version/page`,
    method: 'post',
    data
  })
}

//论文选题最终版本导出
export function exportFinalVersionList(data) {
  return fetch({
    url: `${apiPrefix}version/exportFinalVersionList`,
    method: 'post',
    responseType: 'blob',
    data
  }).then(res => {
    UTILS.downloadFile(res, 'RequireFinalVersionList.xlsx', 'application/vnd.ms-excel;charset=utf-8');
  });
}

//查询该学生最终版本信息
export function getFinalVersionInfo() {
  return fetch({
    url: `${apiPrefix}version/info/finalVersion`,
    method: 'post'
  })
}

export function modifyWithdraw(data) {
    return fetch({
        url: `${apiPrefix}version/withdraw`,
        method: 'put',
        data
    })
}